package com.flexmytalk.sys.user.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.flexmytalk.sys.user.pojo.User;


import flex.messaging.FlexContext;
@SuppressWarnings("unchecked")
public class UserService  {
	private List<User> users=new ArrayList<User>(2000);
	public void createUser(String username,String password)
	{
		try
		{
		    users.add(new User(username,password));
		    setApplication("users", users);
		    System.out.println(users.size()+"==================");
			if(getApplication("users")!=null)
			{
				users=(ArrayList<User>)getApplication("users");
				for(User u:users)
				{
					System.out.println(u.getUsername()+"ll");
				}
			}
		}
		catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
	public List<User> getUser(String key)
	{
			if(getApplication("users")!=null)
			{
				return (ArrayList<User>)getApplication(key);
			}
			return null;
	}
	protected void setApplication(String key, Object obj) {
		FlexContext.getServletContext().setAttribute(key,obj);
	}
	protected Object getApplication(String key) {
		return FlexContext.getServletContext().getAttribute(key);
	}
	
}
